@extends("layout.admin")

@section("title")
    岗位列表
@endsection

@section("content")
    <style>
        .layui-form-switch {
            border-radius: 6px !important;
        }
    </style>
    {{--列表--}}
    <div class="layui-card-body ">
        <script type="text/html" id="toolbar">
            <div class="layui-btn-container">
                @if(_can('admin.version.create'))<a class="layui-btn layui-btn-sm" onclick="admin.openLayerForm('{{route("admin.version.create")}}', '添加题库版本', 'POST', '600px', '450px')"><i class="layui-icon"></i>添加题库版本</a>@endif
            </div>
        </script>
        <table lay-filter="table-hide" style="display: none"  lay-data="{height:'full-310', cellMinWidth: 80,toolbar: '#toolbar',defaultToolbar:['filter'],limit:{{$data['per_page']}}}">
            <thead>
            <tr>
                <th lay-data="{field:'id',width:80, fixed: 'left', unresize: true, sort: true}">编号</th>
                <th lay-data="{field:'name'}">名称</th>
                <th lay-data="{field:'usable'}">状态</th>
                <th lay-data="{field:'remark'}">备注</th>
                <th lay-data="{field:'created_at'}">创建时间</th>
                <th lay-data="{field:'updated_at'}">更新时间</th>
                <th lay-data="{field:'op',fixed: 'right', width:220, align:'center'}">操作</th>
            </tr>
            </thead>
            <tbody>
            @foreach ($data['data'] as $vo)
                <tr>
                    <td>{{ $vo['id'] }}</td>
                    <td>{{ $vo['version'] }}</td>
                    <td>@if(_can('admin.version.update'))
                            <input type="checkbox" name="open" lay-filter="switchTest" value='{{ $vo['id'] }}' lay-skin="switch" lay-text="启用|禁用" @if($vo['usable'] == 1)checked="checked"@endif>
                        @else
                            @if($vo['usable'] == 0)启用@else禁用@endif
                        @endif
                    </td>
                    <td>{{ $vo['remark'] }}</td>
                    <td>{{ $vo['created_at'] }}</td>
                    <td>{{ $vo['updated_at'] }}</td>
                    <td>
                        @if(_can('admin.version.update'))<a class="layui-btn layui-btn-xs" onclick="admin.openLayerForm('{{ route("admin.version.update",['id' => $vo['id']]) }}', '编辑', 'POST', '600px', '450px')">编辑</a>@endif
                        @if(_can('admin.version.destroy'))<a class="layui-btn layui-btn-xs layui-btn-danger" onclick="admin.tableDataDelete('{{ route("admin.version.destroy", ['id' => $vo['id']]) }}', this,'确认删除吗')">删除</a>@endif
                    </td>
                </tr>
            @endforeach
            </tbody>
        </table>
        @include("layout.page")
    </div>
@endsection

@section('script')
    <script>
        var idx=-1;
        layui.use(['form', 'table', 'layer'], function () {
            var table = layui.table;
            var form = layui.form;
            table.init("table-hide");
            admin.paginate("{{ $data['total'] }}", "{{ $data['current_page'] }}", "{{ $data['per_page'] }}");
            form.on('switch(switchTest)', function(data){
                var usable = this.checked?'1':'0';
                var id = data.value;
                $.post('{{route("admin.version.update.attach")}}', {usable:usable,id:id,_token:'{{ csrf_token() }}'},function(data){
                    if(data.code < 0){
                        layer.msg(data.msg, {icon:5,time: 1500});
                    }
                })
            });
        });
    </script>
    <script src="{{asset('js/layCommon.js')}}"></script>
@endsection

